import Cookies from 'js-cookie'
import { encrypt, decrypt } from '../utils/tools'

const TokenKey = 'Admin-Token'
const UserKey = 'User'
const RolesKey = 'Hello-World'
export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function getUser () {
    return JSON.parse(Cookies.get(UserKey) || '{}')
}

export function setUser (user) {
    return Cookies.set(UserKey, JSON.stringify(user))
}

export function removeUser () {
    return Cookies.remove(UserKey)
}

export function getRoles () {
    return JSON.parse(decrypt(Cookies.get(RolesKey))||'[]')
}

export function setRoles (roles) {
    return Cookies.set(RolesKey, encrypt(JSON.stringify(roles)))
}

export function removeRoles () {
    return Cookies.remove(RolesKey)
}
